import javax.crypto.spec.PSource;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: GodK
 * Date: 2024-06-14
 * Time: 20:22
 */
public class Test {
    public static void main(String[] args) {
//        int[] nums = {0, 0, 1, 1, 1, 1, 2, 3, 3};
//        int n = nums.length;
//        if (n <= 2) {
//            System.out.println(n);
//        }
//        int slow = 2, fast = 2;
//        while (fast < n) {
//            if (nums[slow - 2] != nums[fast]) {
//                nums[slow] = nums[fast];
//                slow++;
//            }
//            fast++;
//        }
//        System.out.println(fast);
        int[] prices = {7,1,5,3,6,4};
        int n = prices.length;
        int[] f = new int[n];
        int[] g = new int[n];
        int ret = 0;
        f[0] -= prices[0];
        for (int i = 1; i < n; i++) {
            f[i] = Math.max(f[i - 1], g[i - 1] - prices[i]);
            g[i] = Math.max(f[i - 1] + prices[i], g[i - 1]);
            ret = Math.max(ret, Math.max(f[i], g[i]));
        }
        System.out.println(ret);
    }
}
